package com.ayuku.commons.business.Loginlog;

import java.util.List;

import com.ayuku.commons.AyukuDB;
import com.ayuku.retail.persistence.model.LoginLog;

public class LoginLogImpl {
	public static List<LoginLog> getList(String arg) throws Exception {
		List<LoginLog> lst = AyukuDB.getPersist().readList(LoginLog.class,
				"SELECT * FROM login_log WHERE order by id desc LIMIT 10000",
				new Object[] { arg, arg });
		return lst;
	}

	public static LoginLog getById(String key) throws Exception {
		LoginLog pj = (LoginLog) AyukuDB.getPersist().readByPrimaryKey(
				LoginLog.class, new Object[] { key });
		return pj;
	}

	public static Integer add(LoginLog pj) throws Exception {
		
		return AyukuDB.getPersist().insert(pj);
	}

	public static Integer update(LoginLog pj) throws Exception {
		return AyukuDB.getPersist().update(pj);
	}

	public static Integer delete(String key) throws Exception {
		return AyukuDB.getPersist().executeUpdate(
				"delete from login_log where id=?", key);
	}

	public static int delete(List<String> ids) throws Exception {
		int n = 0;
		try {
			AyukuDB.getPersist().setAutoCommit(false);
			for (int j = 0; j < ids.size(); j++) {
				String key = ids.get(j);
				n += delete(key);
			}
			AyukuDB.getPersist().commit();
		} catch (Exception e) {
			e.printStackTrace();
			AyukuDB.getPersist().rollback();
			throw new Exception();
		} finally {
			AyukuDB.getPersist().setAutoCommit(true);
		}
		return n;
	}
}
